<!DOCTYPE html>
<html>
  <head>
    <title>欢迎使用1</title>
	
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
  </head>
  
  <body>
    <form class="layui-form"  action="">
      <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
          <input type="text" name="devCode" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
          <input type="password" name="devPassword" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>
      <script src="../js/common.js" charset="utf-8"></script>
      <script src="../layui/layui.js" charset="utf-8"></script>
      <script>
        layui.use(['form', 'layedit', 'laydate'], function(){
          var form = layui.form
          ,layer = layui.layer
          ,$ = layui.$
          //监听提交
          form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
              title: '最终的提交信息'
            })
            $.ajax({
              url: appServerUrl + "/dev/dologin2",
              data: data.field,
              type: 'post',
              dataType: 'json',
              success: function(result) {
                if(result.status == 200) {
                  sessionStorage.setItem('userName', result.data.devName)
                  location.href = 'dev/index.html'
                } else {
                  layer.alert('用户名或密码错误')
                }
              },
              error: function (xhr) {
                console.log(xhr)
                layer.alert('error')
              }
            });
            return false;
          });
        
      });
      </script>       
    </body>
</html>
